#!/usr/bin/env python3
"""
依赖安装脚本 - 使用国内镜像源
"""

import subprocess
import sys
import os

def install_dependencies():
    """安装项目依赖"""
    print("正在安装项目依赖...")
    
    # 使用清华镜像源
    pip_install_cmd = [
        sys.executable, "-m", "pip", "install", 
        "-i", "https://pypi.tuna.tsinghua.edu.cn/simple",
        "-r", "requirements.txt"
    ]
    
    try:
        subprocess.run(pip_install_cmd, check=True)
        print("依赖安装完成！")
    except subprocess.CalledProcessError as e:
        print(f"依赖安装失败: {e}")
        return False
    
    return True

def download_yolo_model():
    """下载YOLO模型"""
    print("正在下载YOLO模型...")
    
    try:
        from ultralytics import YOLO
        model = YOLO('yolov8n.pt')
        print("YOLO模型下载完成！")
        return True
    except Exception as e:
        print(f"YOLO模型下载失败: {e}")
        return False

def main():
    """主函数"""
    print("=" * 50)
    print("目标跟踪系统 - 依赖安装")
    print("=" * 50)
    
    # 检查Python版本
    if sys.version_info < (3, 8):
        print("错误: 需要Python 3.8或更高版本")
        return
    
    print(f"Python版本: {sys.version}")
    
    # 安装依赖
    if not install_dependencies():
        print("依赖安装失败，请检查网络连接")
        return
    
    # 下载YOLO模型
    if not download_yolo_model():
        print("YOLO模型下载失败，请检查网络连接")
        return
    
    print("=" * 50)
    print("安装完成！现在可以运行 python main.py")
    print("=" * 50)

if __name__ == "__main__":
    main()
